'use strict';

const Controller = require('egg').Controller;
const moment = require('moment');

class GoodController extends Controller {
  async list() {
    const { ctx } = this;
    const { pageNo, pageSize } = ctx.request.query;
    const result = await ctx.service.goods.list(pageNo, pageSize);
    ctx.success('ok', {
      ...result,
      numberOfPages: undefined,
      pageSize: result.numberOfPages,
      pageNo,
    });
  }
  async inStock() {
    const { ctx } = this;
    const result = await ctx.service.goods.searchGoodInStock();
    ctx.body = result;
  }
  async testAddTask() {
    const { ctx, app } = this;
    try {
      const result = await app.mysql.insert('day_mess', {
        message: `一天下来的统计:爬取次数:-${1}-次;状态:-${2}-`,
        created_time: moment().format('YYYY-MM-DD HH:mm:ss'),
      });
      ctx.body = result;
    } catch (err) {
      ctx.body = err;
    }
  }
  async getData() {
    const { ctx } = this;
    const data = ctx.helper.sha256('yjs10086');
    ctx.body = data;
  }
}

module.exports = GoodController;
